package kov.core.body.zy
{
	import com.riaoo.events.AnimationEvent;
	
	import flash.display.Bitmap;
	import flash.display.BitmapData;
	
	import kov.core.BodyState;
	import kov.core.IBody;
	import kov.core.StateCommand;
	import kov.core.body.StateEnum;
	
	public class ZYFangShou extends BodyState
	{
		[Embed("../../../../../assets/zy/fangshou/0.gif")]
		private var Frame0:Class;
		
		public function ZYFangShou(body:IBody, priority:int=1)
		{
			super(StateEnum.FANG_SHOU, body, priority);
			createRenderer();
		}
		
		// 创建渲染帧。
		private function createRenderer():void
		{
			var f0:BitmapData = (new Frame0() as Bitmap).bitmapData;
			this.renderer.push(f0);
			this.renderer.push(f0);
		}
		
		override public function execute():void
		{
			this.body.renderer.frameSequence = this.renderer;
			this.body.renderer.delay = 200;
			this.body.renderer.offsetX = 39;
			this.body.renderer.offsetY = 90;
			this.body.renderer.gotoAndPlay(0);
			this.body.renderer.addEventListener(AnimationEvent.ANIMATION_END, onAnimationEnd);
		}
		
		override public function exit():void
		{
			this.body.renderer.removeEventListener(AnimationEvent.ANIMATION_END, onAnimationEnd);
		}
		
		private function onAnimationEnd(event:AnimationEvent):void
		{
			var cmd:StateCommand = new StateCommand(StateEnum.XING_ZOU);
			this.body.executeStateCommand(cmd);
		}
		
	}
}